package com.wan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wan.entity.GameUser;
import com.wan.service.GameUserService;
import com.wan.service.IGameLoginService;
import com.wan.util.JwtTokenUtils;
import entity.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author xzx
 * @date 2021/4/14 13:10
 */
@Service
public class GameLoginServiceImpl implements IGameLoginService {
    @Autowired
    private GameUserService gameUserService;
    @Override
    public ResultBean gameLogin(String number, String password) {
        QueryWrapper<GameUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("account_number",number);
        queryWrapper.eq("password",password);
        GameUser user = gameUserService.getOne(queryWrapper);
        if (Objects.isNull(user)){
            return new ResultBean(1001,"登录失败");
        }
        String token = JwtTokenUtils.signShow(user.getId(),user.getNickName());
        Integer userId = JwtTokenUtils.getOpenId(token);
        return new ResultBean(200,"登录成功",token);
    }
}
